package cn.edu.zut.cs;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/MyServlet")
public class MyServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String inputText = req.getParameter("input_text");

        System.out.println("用户输入的内容是：" + inputText);
        resp.setContentType("text/html");
        resp.setCharacterEncoding("UTF-8");
        String outputHtml = "<html><head><title>处理结果</title></head>"
                + "<body><p>你输入的字符串是：" + inputText + "</p></body></html>";
        resp.getWriter().write(outputHtml);
    }

}